<?php
    include_once("db_connect.php");
    $postdata = file_get_contents("php://input");
    if(isset($postdata) && !empty($postdata)){
        $request = json_decode($postdata);
        $username = mysqli_real_escape_string($mysqli, trim($request->username));
        $password = mysqli_real_escape_string($mysqli, trim($request->password));
        $phone = trim($request->phone);

        if($username == "admin" && $password == "admin"){
            $sql = "INSERT INTO login_user (username, password, phone, accesstoken) VALUES ('$username', '$password', '$phone', 1)";
        }else{
            $sql = "INSERT INTO login_user (username, password, phone, accesstoken) VALUES ('$username', '$password', '$phone', 2)";
        }
        
        if($mysqli->query($sql)){
            $data = array('message' => 'success');
            echo json_encode($data);
        }else{
            $data = array('message'=> 'error');
            echo json_encode($data);
        }
    }
?>